<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Main</title>
<style>
<!--
div {
	position: relative;
	top: 0px;
	left: 20px
}
-->
</style>
</head>
<body>
	<p>Hello Main HTML !!!</p>
	<a id="signOutLink" href='/logOut'>サインアウト</a>
	<p id="loadingArea" />
	<p>フォルダリスト</p>
	<a href="#" onclick="triggerFetchDocsFeed('root');">refresh</a>
	<a href="#" onclick="stopFetchDocsFeed();">stop loading</a>


	<div id="root"></div>


	<script src="/js/jquery-1.4.4.min.js"></script>
	<script src="/js/jquery.loadingdots-min.js"></script>
	<script>
		var getEx = function(urlString, dataObj, successFn, errorFun) {
			$.ajax({
				type : "GET",
				url : urlString,
				data : dataObj,
				success : successFn,
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert("server error! please refresh view.");
					return;
				},
				complete : function(xMLHttpRequestObj, textStatusObj) {
					return;
				}
			});
		};

		var stopFetchDocsFeed = function() {
			$("#teminated").remove();
			$("*[name=getChild]").unbind("click");
			$("*[name=getChild]").click(function() {
				triggerFetchDocsFeed($(this).attr("folderId"));
			});
			$("*[name=applyGroup]").unbind("click");
			$("*[name=applyGroup]").click(function() {
				applyGroup($(this).attr("aclFeedLink"),$(this));
			});

			$("#loadingArea").loadingdots({
				mode : "stop"
			});
		};

		var triggerFetchDocsFeed = function(parentFolderId) {
			$("#" + parentFolderId).empty();
			$("#loadingArea").loadingdots();
			fetchDocsFeed(parentFolderId, "");
		};

		var applyGroup = function(aclFeedLinkString,buttonObj) {
			getEx("/ajax/html/docs/applyGroupAcl", {
				aclFeedLink : aclFeedLinkString
				}, function(data){
					fetchDocsFeed(buttonObj.attr("folderId"));
				},null
			);

		}

		var fetchDocsFeed = function(parentFolderIdString, crawlSessionString) {
			var parentE = $("#" + parentFolderIdString);
			getEx("/ajax/html/docs/docsFeed", {
				crawlSession : crawlSessionString,
				parentFolderId : parentFolderIdString
			}, function(data) {
				parentE.append(data);
				var callbackNode = $(data).filter("#callback");
				if (callbackNode.attr("name")) {
					var query = callbackNode.attr("name");
					$("#callback").remove();
					fetchDocsFeed(parentFolderIdString, query);
				} else {
					stopFetchDocsFeed();
				}
			}, null);
		};

		$(function() {
			triggerFetchDocsFeed("root");
		});
	</script>


</body>
</html>
